load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@npm//:rollup/package_json.bzl", rollup = "bin")
load("//tools:defaults.bzl", "ts_project")
load(":e2e.bzl", "e2e_suites")

package(default_visibility = ["//visibility:public"])

ts_project(
    name = "runner",
    testonly = True,
    srcs = [
        "e2e_runner.ts",
    ],
    deps = [
        "//:node_modules/@types/node",
        "//:node_modules/ansi-colors",
        "//:node_modules/fast-glob",
        "//packages/angular_devkit/core",
        "//packages/angular_devkit/core/node",
        "//tests/legacy-cli/e2e/utils",
    ],
)

rollup.rollup(
    name = "runner_bundled",
    testonly = True,
    srcs = [
        "rollup.config.mjs",
        ":runner",
        "//:node_modules/@rollup/plugin-alias",
        "//:node_modules/@rollup/plugin-commonjs",
        "//:node_modules/@rollup/plugin-json",
        "//:node_modules/@rollup/plugin-node-resolve",
        "//:node_modules/fast-glob",
        "//tests/legacy-cli/e2e/initialize",
        "//tests/legacy-cli/e2e/ng-snapshot",
        "//tests/legacy-cli/e2e/setup",
        "//tests/legacy-cli/e2e/tests",
    ],
    args = [
        "--format=cjs",
        "--config=./rollup.config.mjs",
    ],
    chdir = package_name(),
    out_dirs = ["runner_bundled_out"],
    progress_message = "Bundling e2e test runner",
)

directory_path(
    name = "runner_entrypoint",
    testonly = True,
    directory = ":runner_bundled",
    path = "./e2e_runner.js",
)

e2e_suites(
    name = "e2e",
    data = [
        ":runner_bundled",
        "verdaccio.yaml",
        "verdaccio_auth.yaml",

        # Dynamically loaded.
        "//tests/legacy-cli/e2e/assets",
        "//:node_modules/verdaccio",
        "//:node_modules/verdaccio-auth-memory",

        # Extra runtime deps due to bundling issues.
        # TODO: Clean this up.
        "//:node_modules/@verdaccio/config",
        "//:node_modules/express",
    ],
    runner = ":runner_entrypoint",
)
